//
//  swViewController.m
//  swich
//
//  Created by student on 16/2/22.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "swViewController.h"
#import "color1.h"
#import "color2.h"

@interface swViewController ()
@property (nonatomic,strong) color1 *color1;
@property (nonatomic,strong) color2 *color2;
@property (nonatomic,assign) BOOL curcolor;
@end

@implementation swViewController
// 懒加载 节省内存
// 重写getter方法
// 第一次用到这个对象时候去创建这个对象，如果始终没用到这个对象,则不会创建,节省了内存
-(color1 *)color1
{
    if (_color1==nil) {
        _color1=[[color1 alloc]init];
    }
    return _color1;
}

-(color2 *)color2
{
    if (!_color2) {
        _color2=[[color2 alloc]init];
    }
    return _color2;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     [self switch:nil];
}
- (IBAction)switch:(id)sender
{
    // 动画效果 (UIView 简单切换动画)
    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];// 动画的时间
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];// 运动方式
    
    
    if(self.curcolor)
    {
        [self.view insertSubview:self.color1.view atIndex:0];
        [self.color2.view removeFromSuperview];
        // 动画的样式
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    }
    else
    {
        [self.view insertSubview:self.color2.view atIndex:0];
        [self.color1.view removeFromSuperview];
        // 动画的样式
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    }
    [UIView commitAnimations];// 动画开始播放
    self.curcolor = !self.curcolor;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
